﻿using System;
using System.Configuration;
using ASPItalia.ModelVirtualCasting.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ASPItalia.ModelVirtualCasting.Test
{
    [TestClass]
    public class ApplicationContextTest
    {
        private TestContext _testContextInstance;

        public TestContext TestContext
        {
            get { return _testContextInstance; }
            set { _testContextInstance = value; }
        }

        public ApplicationContextTest()
        {
        }

        [ClassInitialize()]
        public static void Initialize(TestContext testContext)
        {
        }

        [ClassCleanup()]
        public static void Cleanup()
        {
        }

        [TestInitialize()]
        public void TestInitialize()
        {
        }

        [TestCleanup()]
        public void TestCleanup()
        {
        }

        [TestMethod]
        public void CandidateRepositoryTest()
        {
            ICandidateRepository repository = ApplicationContext.Current.Candidates;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.CandidateRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.CandidateRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.CandidateRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.CandidateRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceCandidateRepositoryTest()
        {
            ICandidateRepository repository1 = ApplicationContext.Current.Candidates;
            ICandidateRepository repository2 = ApplicationContext.Current.Candidates;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void ModelRepositoryTest()
        {
            IModelRepository repository = ApplicationContext.Current.Models;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.ModelRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.ModelRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.ModelRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.ModelRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceModelRepositoryTest()
        {
            IModelRepository repository1 = ApplicationContext.Current.Models;
            IModelRepository repository2 = ApplicationContext.Current.Models;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void NewsRepositoryTest()
        {
            INewsRepository repository = ApplicationContext.Current.News;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.NewsRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.NewsRepository", repository.ToString());
                }
            }
            else
            {
                Assert.IsTrue(repository.ToString().Contains("Wrapped_INewsRepository"));
            }
        }

        [TestMethod]
        public void MultiInstanceNewsRepositoryTest()
        {
            INewsRepository repository1 = ApplicationContext.Current.News;
            INewsRepository repository2 = ApplicationContext.Current.News;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void RequestRepositoryTest()
        {
            IRequestRepository repository = ApplicationContext.Current.Requests;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.RequestRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.RequestRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.RequestRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.RequestRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceRequestRepositoryTest()
        {
            IRequestRepository repository1 = ApplicationContext.Current.Requests;
            IRequestRepository repository2 = ApplicationContext.Current.Requests;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void CountryRepositoryTest()
        {
            ICountryRepository repository = ApplicationContext.Current.Countries;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.CountryRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.CountryRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.CountryRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.CountryRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceCountryRepositoryTest()
        {
            ICountryRepository repository1 = ApplicationContext.Current.Countries;
            ICountryRepository repository2 = ApplicationContext.Current.Countries;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void JobLevelRepositoryTest()
        {
            IJobLevelRepository repository = ApplicationContext.Current.JobLevels;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.JobLevelRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.JobLevelRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.JobLevelRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.JobLevelRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceJobLevelRepositoryTest()
        {
            IJobLevelRepository repository1 = ApplicationContext.Current.JobLevels;
            IJobLevelRepository repository2 = ApplicationContext.Current.JobLevels;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void JobTypeRepositoryTest()
        {
            IJobTypeRepository repository = ApplicationContext.Current.JobTypes;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.JobTypeRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.JobTypeRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.JobTypeRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.JobTypeRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceJobTypeRepositoryTest()
        {
            IJobTypeRepository repository1 = ApplicationContext.Current.JobTypes;
            IJobTypeRepository repository2 = ApplicationContext.Current.JobTypes;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void LanguageRepositoryTest()
        {
            ILanguageRepository repository = ApplicationContext.Current.Languages;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.LanguageRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.LanguageRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.LanguageRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.LanguageRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceLanguageRepositoryTest()
        {
            ILanguageRepository repository1 = ApplicationContext.Current.Languages;
            ILanguageRepository repository2 = ApplicationContext.Current.Languages;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void PersonRepositoryTest()
        {
            IPersonRepository repository = ApplicationContext.Current.People;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.PersonRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.PersonRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.PersonRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.PersonRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiPersonLanguageRepositoryTest()
        {
            IPersonRepository repository1 = ApplicationContext.Current.People;
            IPersonRepository repository2 = ApplicationContext.Current.People;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void UserRepositoryTest()
        {
            IUserRepository repository = ApplicationContext.Current.Users;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.UserRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.UserRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.UserRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.UserRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceUserRepositoryTest()
        {
            IUserRepository repository1 = ApplicationContext.Current.Users;
            IUserRepository repository2 = ApplicationContext.Current.Users;

            Assert.AreNotSame(repository1, repository2);
        }

        [TestMethod]
        public void UserRoleRepositoryTest()
        {
            IUserRoleRepository repository = ApplicationContext.Current.UserRoles;

            if (ApplicationContext.Current.RepositoryFactoryType.Equals(RepositoryFactoryType.Mef))
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.UserRoleRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.UserRoleRepository", repository.ToString());
                }
            }
            else
            {
                if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.Fake"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.Fake.UserRoleRepository", repository.ToString());
                }
                else if (Configuration.RepositoryAssemblyName.Equals("ASPItalia.ModelVirtualCasting.EntityFramework"))
                {
                    Assert.AreEqual("ASPItalia.ModelVirtualCasting.EntityFramework.UserRoleRepository", repository.ToString());
                }
            }
        }

        [TestMethod]
        public void MultiInstanceUserRoleRepositoryTest()
        {
            IUserRoleRepository repository1 = ApplicationContext.Current.UserRoles;
            IUserRoleRepository repository2 = ApplicationContext.Current.UserRoles;

            Assert.AreNotSame(repository1, repository2);
        }
    }
}
